"""Data processing utilities."""

import json
import math
from texttable import Texttable
from torch import nn

def tab_printer(args):
    """
    Function to print the logs in a nice tabular format.
    :param args: Parameters used for the model.
    """
    args = vars(args)
    keys = sorted(args.keys())
    t = Texttable()
    t.add_rows([["Parameter", "Value"]])
    t.add_rows([[k.replace("_", " ").capitalize(), args[k]] for k in keys])
    print(t.draw())

# def process_pair(path):
#     """
#     Reading a json file with a pair of graphs.
#     :param path: Path to a JSON file.
#     :return data: Dictionary with data.
#     """
#     data = json.load(open(path))
#     return data

def calculate_loss(prediction, target):
    """
    Calculating the squared loss on the normalized GED.
    :param prediction: Predicted log value of GED.
    :param target: Factual log transofmed GED.
    :return score: Squared error.
    """
    crossentropyloss = nn.CrossEntropyLoss()
    score = crossentropyloss(prediction, target)
    return score

# def calculate_normalized_ged(data):
#     """
#     Calculating the normalized GED for a pair of graphs.
#     :param data: Data table.
#     :return norm_ged: Normalized GED score.
#     """
#     norm_ged = data["ged"]/(0.5*(len(data["labels_1"])+len(data["labels_2"])))
#     return norm_ged
